import 'package:flutter/animation.dart';
import 'package:flutter/cupertino.dart';

/**
 *
 * @ProjectName:    flutter_skeleton
 * @Package:
 * @ClassName:      skeleton_animiation
 * @Description:    动画控制器
 * @Author:         孙浩
 * @CreateDate:     4/29/21 2:17 PM
 */
enum SkeletonAnimationStyle {
  shimmer,
  widthChange,
  static,
}

class SkeletonAnimationManager {
  AnimationController _animationController;

  initAnimContainer(TickerProvider vsync,
      {Duration duration, ValueChanged<double> change}) {
    if (duration == null) duration = Duration(seconds: 2);
    _animationController =
        AnimationController(vsync: vsync, duration: duration);
    _animationController?.addListener(() {
      change?.call(_animationController.value);
    });
  }

  void start({bool reverse = false}) {
    _animationController?.repeat(reverse: reverse);
  }

  AnimationController get animationController => _animationController;

  ///结束动画
  void cancel() {
    _animationController?.stop(canceled: true);
    _animationController?.dispose();
    _animationController = null;
  }
}
